package cn.gson.crmdemo.controller.finance;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.Invoice;
import cn.gson.crmdemo.model.service.HkService;
import cn.gson.crmdemo.model.service.HkjlService;
import cn.gson.crmdemo.model.vo.HkjlVo;

@Controller
public class HkjlController {
	@Autowired
	HkService hs;
	@Autowired
	HkjlService ks;
	public Map<String,Object> yy(JSONArray selecthk,Page page) {
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("list",selecthk);
		map.put("total",page.getTotal());
		return map;
	}
	//查询回款记录
	@RequestMapping("hkjl")
	@ResponseBody
	public Map<String,Object>hkjl(Integer pageNum,Integer pasgeSize,String getmoneyDate,Integer payType,Integer fpZt){
		System.err.println(getmoneyDate);
		System.err.println(payType);
		System.err.println(fpZt);

		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=ks.hkjl(getmoneyDate,payType,fpZt);
		
		//创建Map集合
		return this.yy(selecthk, page);
	}
	
	
	//查询回款计划
	@RequestMapping("cxjh")
	@ResponseBody
	public Map<String,Object>cxjh(Integer pageNum,Integer pSize){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pSize);
		//查询数据
		JSONArray selecthk=ks.selectjh();
		//创建Map集合		
		return this.yy(selecthk, page);

	}
	//添加回款记录
			@RequestMapping("tjhkjlqqop")
			public String tjhkjl(HkjlVo tjhkjl) {
				int o=tjhkjl.getOrderId();
				ks.tjhkjl(tjhkjl);
				hs.xgzt(tjhkjl.getGetplanId(),1,o);
				return "redirect:hk?pageNum=1&pasgeSize=7";
			}
	//修改回款记录
			@RequestMapping("tjhkjlxg")
			public String tjhkjlxg(HkjlVo tjhkjl) {
				ks.xghkjl(tjhkjl);
				return"redirect:hkjl?pageNum=1&pasgeSize=7";
				}
	//修改状态
			@RequestMapping("xghkjlzt")
			public String xgzt(int c,int b) {
				ks.xgfpzt(c, b);
				return"redirect:hkjl?pageNum=1&pasgeSize=7";

			}
			//日期模糊查询
			@RequestMapping("sjcxhkjl")
			@ResponseBody
			public Map<String,Object>mhcxsj(Integer pageNum,Integer pasgeSize,String rq){
				//分页
				Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
				//查询数据
				JSONArray selecthk=ks.selectmh("%"+rq+"%");
				//创建Map集合	
				return this.yy(selecthk, page);
			}
			
			//付款方式
			
			@RequestMapping("hkjl-fkfs")
			@ResponseBody
			public Map<String,Object>selectfs(Integer pageNum,Integer pasgeSize,Integer a){
				//分页
				Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
				//查询数据
				JSONArray selecthk=ks.selectfs(a);
				//创建Map集合	
				return this.yy(selecthk, page);
			}
			//付款发票
			@RequestMapping("hkjl-fp")
			@ResponseBody
			public Map<String,Object>selectfp(Integer pageNum,Integer pasgeSize,Integer b){
				//分页
				Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
				//查询数据
				JSONArray selecthk=ks.selectfp(b);
				//创建Map集合	
				return this.yy(selecthk, page);
			}
		
}
